package cn.thomas.clock.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * RabbitMQ配置类
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 交换机名称
     */
    public static final String XINNUO_CLOCK__TOPIC_EXCHANGE = "xinnuo_clock_topic_exchange";

    /**
     * 队列名称
     */
    public static final String ITEM_QUEUE = "clock_in_queue";


    public static final String XINNUO_ROUTING_KEY = "xinnuo.clock.#";


    /*
     * 声明队列
     */
    @Bean("itemQueue")
    public Queue itemQueue() {
        return new Queue(ITEM_QUEUE,true);
    }


    /**
     * 声明交换机
     */
    @Bean("itemTopicExchange")
    public Exchange fanoutExchange() {
        return new FanoutExchange(XINNUO_CLOCK__TOPIC_EXCHANGE);
    }
    /*
     * 绑定队列和交换机
     *
     * @param queue    队列
     * @param exchange 交换机
     */
    @Bean
    public Binding itemQueueExchange() {
        return BindingBuilder.bind(itemQueue()).to(fanoutExchange()).with("").noargs();
    }

}